/*
 * Minion.cpp
 *
 *  Created on: 06/12/2011
 *      Author: arleudo
 */

#include "objetos/Minion.h"

namespace objetos
{
	//--------------------------------------------------------------------------------
	Minion::Minion( sf::Sprite* target )
			: Enemy( target )
	{

	}
	//--------------------------------------------------------------------------------
	Minion::~Minion( void )
	{

	}
	//--------------------------------------------------------------------------------
	void Minion::load( void )
	{
		std::string sourcePath = "resources/iceman/";
		std::string sourceExtension = ".png";

		std::string str = "WalkingRight";
		Asset::getInstance()->loadImages( sourcePath, str, sourceExtension, 12, vecRight );

		setX( 400 );
		setY( 360 );

		Animation* A_RunnerRight = new Animation( vecRight, 0.05 );

		addAnimation( A_RunnerRight );

	}
	//--------------------------------------------------------------------------------
	void Minion::move( void )
	{
		bool apertou = false;

		if ( IS_KEY_DOWN(Right) )
		{
			apertou = true;
			//vel.x += ACCEL;
			if ( vel.x > MAX_VELOCITY )
			{
				vel.x = MAX_VELOCITY;
			}
		}

		if ( IS_KEY_DOWN(Left) )
		{
			apertou = true;
			//vel.x -= ACCEL;
			if ( vel.x < MAX_MINIM )
			{
				vel.x = MAX_MINIM;
			}
		}
		if ( !apertou || ( IS_KEY_DOWN(Right) && IS_KEY_DOWN(Left) ) )
		{
			vel.x = 0;
		}
	}
	//--------------------------------------------------------------------------------
	void Minion::runAnimation( void )
	{
		this->setImage( getAnimation().at( 0 )->run() );
	}
	//--------------------------------------------------------------------------------
	void Minion::update( void )
	{
		if ( getSprite()->GetPosition().x > 1000 )
		{
			getSprite()->SetPosition( getSprite()->GetPosition().x, 400 );
		}

		getSprite()->Move( vel );

		runAnimation();
		move();
	}

} // namespace objetos

